package com.xhl.consul.tool.Mono;

import lombok.extern.slf4j.Slf4j;
import reactor.core.Disposable;
import reactor.core.publisher.Mono;

import java.util.Optional;
import java.util.concurrent.TimeUnit;

/**
 * @Author CazCen
 * @Date 2021/11/26 14:11
 */
@Slf4j
public class MonoTest {

    public static void do1(){
        Mono<Object> empty = Mono.empty();

        empty.subscribe((n)->{
            log.info("执行 do1 n:{}",n);
        });

    }


    public static void do2(){
        Mono<Object> empty = Mono.justOrEmpty("justOrEmpty--do2");

        empty.subscribe((n)->{
            log.info("执行 do2 n:{}",n);
        });

    }

    public static void do3(){

        Mono.justOrEmpty("-------------- 业余草1").subscribe(System.out::println);

        Mono.justOrEmpty(Optional.of(" -------------- 业余草2")).subscribe(System.out::println);


        Mono<Object> objectMono = Mono.justOrEmpty(Optional.empty());

        objectMono.subscribe((n)->{
            log.info("--------- n :{}",n);
        });

    }


    public static void do4(){

        log.info("121212eeeeeeeeeeeee");

        Disposable subscribe = Mono.justOrEmpty("-------------- 业余草1").subscribe(n -> {

            log.info("00000000000");

            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            log.info("00000000000--0000000000000");

        });

        log.info("11111111111");

    }

}
